package hongcaosp.app.android.video.online.presenter;

import android.text.TextUtils;

import hongcaosp.app.android.login.UserToken;
import hongcaosp.app.android.modle.DataCallBack;
import hongcaosp.app.android.modle.bean.Pagebean;
import hongcaosp.app.android.modle.impl.OnlineModelImpl;
import hongcaosp.app.android.video.online.bean.OnlineMusic;
import hongcaosp.app.android.video.online.iview.IOnlineCategoryView;
import xlj.lib.android.base.component.BasePresenter;

public class OnlineCategoryPresenter extends BasePresenter {
    private IOnlineCategoryView view;
    private OnlineModelImpl onlineModel;

    private int id = -1,pageSize = 10,pageNumber = 1;
    private String content;

    public OnlineCategoryPresenter(IOnlineCategoryView view,int id,String content) {
        this.view = view;
        this.id = id;
        this.content = content;
        this.onlineModel = new OnlineModelImpl();
    }

    public void load() {
        pageNumber = 1;
        if (id != -1) {
            rankList();
        } else if (!TextUtils.isEmpty(content)) {
            search();
        }
    }

    public void loadMore() {
        load();
    }

    private void rankList() {
        onlineModel.rankList(UserToken.getDefault().getToken(), id, pageNumber, pageSize, new DataCallBack<Pagebean<OnlineMusic>>() {
            @Override
            public void onGetData(Pagebean<OnlineMusic> data) {
                super.onGetData(data);
                pageNumber ++;
                view.data(data.getList());
            }

            @Override
            public void onFail(int code, String errorMessage) {
                super.onFail(code, errorMessage);
            }
        });
    }

    private void search() {
        onlineModel.search(UserToken.getDefault().getToken(), content, pageNumber, pageSize, new DataCallBack<Pagebean<OnlineMusic>>() {
            @Override
            public void onGetData(Pagebean<OnlineMusic> data) {
                super.onGetData(data);
                pageNumber ++;
                view.data(data.getList());
            }

            @Override
            public void onFail(int code, String errorMessage) {
                super.onFail(code, errorMessage);
            }
        });
    }
}
